import React from 'react'
import { connect } from 'dva'
import { Select } from 'antd'
const Option = Select.Option;


// const industryList = [
// 	{
// 		name: '申万一级行业分类',
// 		value: '38_1'
// 	}, {
// 		name: '申万二级行业分类',
// 		value: '38_2'
// 	}, {
// 		name: '申万一级行业分类(非银金融二级)',
// 		value: '38_99'
// 	}
// ]

/**
 * [IndustrySelect 行业选择框]
 */
class IndustrySelect extends React.Component {
  state = {
    data: this.props.industryList,
    value: this.props.industryList.find(item=>item.key===this.props.industryID),
  }

  

  handleSelect = (value) => {
    this.setState({
      value,
    })
    this.changeRouter(value.key)
  }

  handleChange = (value) => {
    if (!value) {
      this.setState({
        data: [],
        value: { key: '', label: '' },
      })
    }
  }

  changeRouter(val) {
    //  保存查询参数到URL
    const payload=this.props.location
    payload.query.industryID=val
    this.props.dispatch({
      type: `app/changeRouter`,
      payload
    })
  }
  render() {
    const { value, data } = this.state
    console.log(900,this.props.location);
    
    return (
      <Select
        style={{ width: 180 }}
        onSelect={this.handleSelect.bind(this)}
        labelInValue
        value={value}
        onChange={this.handleChange.bind(this)}
      >
        {
          data.map((item, index) => <Option value={item.key} key={index}>{item.label}</Option>)
        }
      </Select>
    )
  }
}
IndustrySelect.defaultProps = {
  industryID:'38_1',
  industryList : [
	{
		label: '申万一级行业分类',
		key: '38_1'
	}, {
		label: '申万二级行业分类',
		key: '38_2'
	}, {
		label: '申万一级行业分类(非银金融二级)',
		key: '38_99'
	}
],

  location: {
    pathname: '/',
    query: {},
  },
}

export default connect()(IndustrySelect)
